#!/usr/bin/env ruby
#
# Test for util.rb in converting times
#

require 'test/unit'
require File.join(File.dirname(__FILE__),'../script/util')

include Util

class UtilTimeTest < Test::Unit::TestCase 
  
  def setup

  end
  
  def teardown

  end

  def test_nil
    assert_nil convert_time(nil)
  end

  def test_empty
    assert_equal '', convert_time('')
  end

  def test_1300
    arr = [
           "1300",
           "1 - 2 p.m.",
           "1 p.m.",
           "1-2 p.m.",
           "1-2:15 p.m.",
           "1:00-2:00 p.m."
          ]
    run_tests "1300", arr
  end

  def test_1000
    arr = [
           "1000",
           "10 - 11 a.m.",
           "10 - 11 a.m., no break",
           "10 a.m.",
           "10 a.m. Beg. 8:45-9:30 a.m.",
           "10 a.m., Beg. 8:30 a.m.",
           "10- 11 a.m.",
           "10-11 a.m.",
           "10-11:00 a.m.",
           "10-11:15 a.m.",
           "10:00 a.m.",
           "10:00 a.m. beg. 9:00 a.m.",
           "10:00 a.m., Beg. 8:45 a.m.",
           "10:00-11:00 a.m.",
           "10:00-11:30 a.m."
          ]
    run_tests "1000", arr
  end

  def test_1015
    arr = [
           "1015 AM",
           "1015 a.m.",
           "1015 am",
           "1015 A.M.",
           "1015",
           "10:15 a.m.",
           "10:15-11:30 a.m."
          ]
    run_tests "1015", arr
  end

  def test_1030
    arr = [
           "1030 AM",
           "1030 a.m.",
           "1030 am",
           "1030 A.M.",
           "1030",
           "10:30 - 11:30 a.m., Beg. 9:15a.m.",
           "10:30 -11:30 a.m.",
           "10:30 a.m.",
           "10:30-11:30 a.m.",
           "10:30-11:30 a.m., Beg. 9:15 am",
           "10:30-NOON"
          ]
    run_tests "1030", arr
  end

  def test_2200
    arr = [
           "2200",
           "10 p.m.",
           "10:00 pm",
          ]
    run_tests "2200", arr
  end

  def test_1100
    arr = [
           "1100 AM",
           "1100 a.m.",
           "1100 am",
           "1100 A.M.",
           "1100",
           "11 a.m.",
           "11 a.m.-12:15 p.m.",
           "11-Noon",
           "11-noon",
           "11:00 - Noon",
           "11:00 a.m-NOON",
           "11:00 a.m.",
           "11:00-NOON",
          ]
    run_tests "1100", arr
  end

  def test_2300
    arr = [
           "2300",
           "11:00 p.m.",
          ]
    run_tests "2300", arr
  end

  def test_1145
    arr = [
           "1145 AM",
           "1145 a.m.",
           "1145 am",
           "1145 A.M.",
           "1145",
           "11:45 a.m.-12:45 p.m.",
           "11:45 - 12:45",
          ]
    run_tests "1145", arr
  end

  def test_1130
    arr = [
           "1130 AM",
           "1130 a.m.",
           "1130 am",
           "1130 A.M.",
           "1130",
           "11:30 a.m.",
           "11:30 a.m.-12:30 p.m.",
           "11:30 a.m.-12:30 pm",
          ]
    run_tests "1130", arr
  end

  def test_1330
    arr = [
           "1330",
           "1:30-2:30 p.m."
          ]
    run_tests "1330", arr
  end

  def test_1400
    arr = [
           "1400",
           "2 - 3 p.m.",
           "2 p.m.",
           "2-3 p.m.",
           "2:00 p.m.",
           "2:00; 5:30; 10:30 p.m." # TODO
          ]
    run_tests "1400", arr
  end

  def test_1430
    arr = [
           "1430",
           "2:30 p.m.",
           "2:30-3:30 p.m."
          ]
    run_tests "1430", arr
  end

  def test_1500
    arr = [
           "1500",
           "3 p.m.",
           "3-4 p.m.",
           "3:00 p.m."
          ]
    run_tests "1500", arr
  end

  def test_1530
    arr = [
           "1530",
           "3:30 p.m.",
           "3:30-4:30 p.m."
          ]
    run_tests "1530", arr
  end

  def test_1600
    arr = [
           "1600",
           "4-5 p.m.",
           "4-5:15 p.m.",
           "4:00 p.m."
          ]
    run_tests "1600", arr
  end

  def test_1630
    arr = [
           "1630",
           "4:30-5:30 p.m."
          ]
    run_tests "1630", arr
  end

  def test_1700
    arr = [
           "1700",
           "5 p.m.",
           "5-6 p.m.",
           "5-6:15 p.m.",
           "5:00 - 6:00 p.m.",
           "5:00 p.m.",
           "5:00-6:00 p.m."
          ]
    run_tests "1700", arr
  end

  def test_1715
    arr = [
           "1715",
           "5:15-6:15 p.m."
          ]
    run_tests "1715", arr
  end

  def test_1730
    arr = [
           "1730",
           "5:30 - 6:30 p.m.",
           "5:30 -6:30 p.m.",
           "5:30 p.m.",
           "5:30-6:30 p.m.",
           "5:30-6:30 p.m. 10:30 p.m.",
           "5:30-6:45 p.m."
          ]
    run_tests "1730", arr
  end

  def test_1745
    arr = [
           "1745",
           "5:45-6:45 p.m."
          ]
    run_tests "1745", arr
  end

  def test_0500
    arr = [
           "0500",
           "5:00 a.m.",
          ]
    run_tests "0500",arr
  end

  def test_0600
    arr = [
           "600 AM",
           "600 am",
           "600 A.M.",
           "600 a.m.",
           "0600",
           "6:00-6:45  a.m.",
           "6:00-6:45 a.m.",
           "6:00 - 6:45 a.m.",
           "6-7 a.m.",
           "6 a.m.",
           "6 a.m. and 7 a.m.",
           "6 a.m.and  7 a.m"
          ]
    run_tests "0600", arr
  end

  def test_0630
    arr = [
           "0630",
           "6:30-7:30 a.m.",
           "6:30 a.m."
          ]
    run_tests "0630", arr
  end

  def test_0645
    arr = [
           "0645",
           "6:45-7:45 a.m.",
           "6:45-7:45 a.m. Tapes",
           "6:45 -7:45 a.m.",
           "6:45 a.m.-7:45 a.m."
          ]
    run_tests "0645", arr
  end

  def test_1800
    arr = [
           "1800",
           "6-7 p.m.",
           "6-7:00 p.m.",
           "6-7:15 p.m.",
           "6:00 - 7:00 p.m.",
           "6:00 -7:00 p.m.",
           "6:00 p.m.",
           "6:00 p.m., not holidays",
           "6 - 7 p.m.",
           "6 - 7:15 p.m.",
           "6 p.m.",
           "6-7  p.m."
          ]
    run_tests "1800", arr
  end

  def test_1815
    arr = [
           "1815",
           "6:15 p.m.",
           "6:15-7:30 p.m."
          ]
    run_tests "1815", arr
  end

  def test_1830
    arr = [
           "1830",
           "6:30 - 7:30 PM",
           "6:30 - 7:30 p.m.",
           "6:30 - 7:45 p.m.",
           "6:30 - 8 p.m.",
           "6:30 -7:30 p.m.",
           "6:30 p.m.",
           "6:30-7:30 P.M.",
           "6:30-7:30 p.m.",
           "6:30-7:45 p.m.",
           "6:30-8 p.m."
          ]
    run_tests "1830", arr
  end

  def test_1845
    arr = [
           "1845",
           "6:45 p.m.",
           "6:45-7:45 p.m."
          ]
    run_tests "1845", arr
  end

  def test_1855
    arr = [
           "1855",
           "6:55-7:55 p.m."
          ]
    run_tests "1855", arr
  end

  def test_1900
    arr = [
           "1900",
           "7:00-8:30 p.m.",
           "7:00-8:00 p.m.",
           "7:00 p.m. Beg. 6-7 p.m.",
           "7:00 p.m. Beg. 6 p.m.",
           "7:00 p.m.",
           "7:00 - 8:30 p.m.",
           "7:00 - 8:00 p.m.",
           "7:00 - 8 p.m.",
           "7-8:30 p.m.",
           "7-8:20 p.m.",
           "7-8:15 p.m.",
           "7 - 8 :15 p.m.",
           "7 - 8 p.m.",
           "7 - 8:15 p.m.",
           "7 p.m.",
           "7 p.m., Beg. 6 p.m.",
           "7-7:45 p.m.",
           "7-8 PM",
           "7-8 p.m.",
           "7-8 p.m., Beg. 5:45-6:45 p.m.",
           "7-8 p.m., Beg. 6-6:45 p.m.",
           "7-8 p.m., Beg.6-6:45 pm"
          ]
    run_tests "1900", arr
  end

  def test_0700
    arr = [
           "0700",
           "7a.m. 5 p.m.",
           "7 a.m, Noon, 5 p.m.",
           "7 a.m.",
           "7 a.m.& 5 p.m.",
           "7 a.m., NOON 5 p.m.",
           "7 a.m., NOON, 5 p.m.",
           "7 a.m., NOON, 5 p.m. 8 p.m.",
           "7-8 a.m.",
           "7-8 a.m. 6 a.m.",
           "7-8 a.m., 6 a.m.",
           "7-8 a.m.6 a.m.",
           "7-8:00 a.m.",
           "7-8:15 a.m.",
           "7-8a.m.",
           "7:00 - 8:00 a.m. and NOON-1 p.m.",
           "7:00 - 8:00 a.m. and Noon-1 p.m.",
           "7:00 a.m.",
           "7:00-8:00 a.m.",
           "7:00-8:00 a.m. and NOON-1 p.m.",
           "7:00-8:15 a.m."
          ]
    run_tests "0700", arr
  end

  def test_0715
    arr = [
           "0715",
           "7:15 - 8:15 a.m.",
           "7:15 a.m",
           "7:15 a.m.",
           "7:15-8 a.m.",
           "7:15-8 a.m., No Holidays",
           "7:15-8:15 a.m."
          ]
    run_tests "0715", arr
  end

  def test_0730
    arr = [
           "0730",
           "7:30 - 8:30 a.m.",
           "7:30 a.m.",
           "7:30 a.m., Trad. 1st Mon.",
           "7:30-8:15 a.m.",
           "7:30-8:30  a.m.",
           "7:30-8:30 a.m."
          ]
    run_tests "0730", arr
  end

  def test_1915
    arr = [
           "1915",
           "7:15 - 8:15 p.m.",
           "7:15 -8:15 p.m.",
           "7:15 p.m.",
           "7:15-8:15 p.m."
          ]
    run_tests "1915", arr
  end


  def test_1930
    arr = [
           "1930",
           "7:30, Beg. 6 - 7 p.m.",
           "7.30-8:30 p.m., Beg., 6-7 p.m.,",
           "7;30-8:30 p.m.",
           "7:30p.m.",
           "7:30:p.m.",
           "7:30:8:30 p.m.",
           "7:30-9:00 p.m.",
           "7:30-9 p.m., beg. 6:15-7:15 p.m.",
           "7:30-8:45 p.m.",
           "7:30-8:30 p.m.No mtg 3rd Tue.",
           "7:30-8:30 p.m., Beg. 6:30 p.m.",
           "7:30-8:30 p.m. Beg. 6:15-7:00",
           "7:30-8:30 p.m. Beg. 6:15 p.m.",
           "7:30-8:30 p.m.",
           "7:30-8:30  p.m.",
           "7:30 p.m.,Beg 6:15 p.m.",
           "7:30 p.m., Trad. 1st Sun.",
           "7:30 p.m., Begin. 6:30 p.m.",
           "7:30 p.m., Beg. 6:30 p.m.",
           "7:30 p.m., Beg. 6:15 p.m.",
           "7:30 p.m., Beg. 6-7 p.m.",
           "7:30 p.m. p.m.",
           "7:30 p.m. Beg.6 p.m.",
           "7:30 p.m. Beg. 6:15",
           "7:30 p.m. Beg. 6-7 p.m.",
           "7:30 p.m. - 8:30 p.m.",
           "7:30 p.m.",
           "7:30 p m.",
           "7:30 - 9:00 p.m.",
           "7:30 - 9 p.m.",
           "7:30 - 8:45 p.m.",
           "7:30 - 8:30 p.m.",
           "7:30  p.m."
          ]
    run_tests "1930", arr
  end

  def test_1945
    arr = [
           "1945",
           "7:45-9:15 p.m.",
           "7:45-9:00 p.m.",
           "7:45-9 p.m.",
           "7:45 p.m.",
           "7:45 - 9p.m.",
           "7:45 - 9:00 p.m.",
           "7:45 - 9 pm",
          ]
    run_tests "1945",arr
  end

  def test_2345
    arr = [
           "2345",
           "11:45-12:45 p.m."
          ]
    run_tests "2345",arr
  end

  def test_2015
    arr = [
           "2015",
           "8:15-9:30 p.m.",
          ]
    run_tests "2015", arr
  end

  def test_2000
    arr = [
           "2000",
           "8:00-9:15 p.m",
           "8:00-9:00 p.m., Beg. 7 p.m.",
           "8:00-9:00 p.m.",
           "8:00-10:00 p.m.",
           "8:00- 9:15 p.m.",
           "8:00 p.m., Beg., 7:00 p.m.",
           "8:00 p.m., Beg. 7:00 p.m.",
           "8:00 p.m., Beg. 6:30 p.m.",
           "8:00 p.m., Beg. 6:30",
           "8:00 p.m. and NOON",
           "8:00 p.m. Beg. 7:00 p.m.",
           "8:00 p.m. Beg. 6:45-7:30 p.m.",
           "8:00 p.m. Beg. 6:45 p.m.",
           "8:00 p.m.",
           "8:00 p.m",
           "8-9:30 p.m.",
           "8-9:15 p.m., Beg. 6:45 p.m.",
           "8-9:15 p.m.",
           "8-9:00 p.m.",
           "8-9 p.m., Beg. 7:00 p.m.",
           "8-9 p.m., Beg. 6:45 p.m.",
           "8-9 p.m., Beg. 6:30 p.m.",
           "8-9 p.m., Beg 7:00 p.m.",
           "8-9 p.m. Beg. 7 p.m.",
           "8-9 p.m.",
           "8- 9 p.m., Beg. 6:30 p.m.",
           "8 p.m., beg. 7 pm",
           "8 p.m., Beg. 7 p.m",
           "8 p.m.(STEP First Week of Month)",
           "8 p.m. No Holidays",
           "8 p.m. Beg. 7 p.m.",
           "8 p.m. Beg 6:45",
           "8 p.m. (NOT 3rd Fri.)",
           "8 p.m.",
           "8 -9:15 p.m.",
           "8 - 9 p.m., Beg. 7 p.m.",
           "8 - 9 p.m., Beg. 6:30 - 7:30 p.m. ",
           "8 - 9 p.m. Beg. 7 p.m.",
           "8 - 9 p.m."
          ]
    run_tests "2000", arr
  end

  def test_2030
    arr = [
           "2030",
           "8:30-9:45 p.m. (no break)",
           "8:30-9:30 p.m.",
           "8:30-10:00 p.m., Step 7:15 p.m.",
           "8:30 p.m., beg. 7:30 p.m.",
           "8:30 p.m. Beg. 7-8 p.m.",
           "8:30 p.m.",
           "8:30 - 9:30 p.m.",
          ]
    run_tests "2030", arr
  end

  def test_0800
    arr = [
           "0800",
           "8 a.m.",
           "8-9 a.m.",
           "8:00 a.m.",
           "8:00-9:00 a.m."
          ]
    run_tests "0800", arr
  end

  def test_0830
    arr = [
           "0830",
           "8:30 - 9:30 a.m.",
           "8:30 - 9:30 am",
           "8:30 9:30 a.m.",
           "8:30 a.m.",
           "8:30-9:30 a.m.",
           "8:30-9:45 a.m.",
          ]
    run_tests "0830", arr
  end

  def test_0845
    arr = [
           "0845",
           "8:45 - 10:00 a.m.",
           "8:45 a.m.",
           "8:45-9:45 a.m.",
           "8:45-9:45 a.m.."
          ]
    run_tests "0845",arr
  end

  def test_0900
    arr = [
           "0900",
           "9:00 a.m., Beg. 8 a.m.",
           "9:00 a.m.",
           "9-10:15 a.m.",
           "9-10 a.m. 8-8:45 a.m.",
           "9-10 a.m.",
           "9 a.m.",
          ]
    run_tests "0900", arr
  end

  def test_2100
    arr = [
           "2100",
           "9-10 p.m.",
           "9:00-10:00 p.m."
          ]
    run_tests "2100", arr
  end

  def test_0930
    arr = [
           "0930",
           "9:30 - 10:30 a.m.",
           "9:30 - 10:30 am",
           "9:30 a.m.",
           "9:30-10:30 a.m."
          ]
    run_tests "0930", arr
  end

  def test_1230
    arr = [
           "1230",
           "12:30-1:30 p.m."
          ]
    run_tests "1230", arr
  end

  def test_1200
    arr = [
           "1200",
           "NOON",
           "NOON - 1 p.m.",
           "NOON - 1:15 p.m.",
           "NOON - 1p.m.",
           "NOON - 1p.m. No holidays.",
           "NOON -1 p.m.",
           "NOON -12:45 p.m.",
           "NOON-1 p.m.",
           "NOON-1 p.m., 11-11:45 a.m.F328",
           "NOON-1:15 p.m.",
           "Noon",
           "Noon - 1 p.m.",
           "Noon - 1:00 p.m.",
           "Noon - 1p.m.",
           "Noon, not holidays",
           "Noon-1 p.m.",
           "Noon-1 p.m. ",
           "Noon-1:00 p.m.",

           "12-1 p.m.",
           "12-1:00 p.m.",
          ]
    run_tests "1200", arr
  end

  def test_1210
    arr = [
           "1210",
           "12:10-1 p.m.",
          ]
    run_tests "1210",arr
  end

  def test_1215
    arr = [
           "1215",
           "12:15 -1:15 p.m.",
           "12:15 p.m.",
           "12:15-1:15 p.m.",
          ]
    run_tests "1215",arr
  end

  def run_test(want,test)
    have = Util::convert_time test
    assert_equal want, have
  end

  def run_tests(want,tests)
    tests.each { |test| run_test want,test }
  end


end
